//package work.timejay.user.utils;
//
//import com.alibaba.fastjson.JSONObject;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.producer.TransactionSendResult;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Component;
//import work.timejay.user.entity.User;
//import work.timejay.user.service.UserService;
//import work.timejay.user.vo.UserSend;
//
//import javax.annotation.Resource;
//import java.util.Random;
//import java.util.UUID;
//
///**
// * @className:RocketMQUtils.java
// * @author:王文杰
// * @version:1.0.0
// * @description:rocketmq工具类
// * @createTime 2022年01月02日 15:32:00
// */
//@Component
//@Slf4j
//public class RocketMQSendUtils {
//    @Resource
//    private  RocketMQTemplate rocketMQTemplate;
//
//    /**
//     * 发送事务消息
//     */
//    public  TransactionSendResult sendTransactionMessage(Object obj,String topic,String tag){
//        log.info("【事务消息内容】 obj:{},topic:{},tag:{}",obj.toString(),topic,tag);
//        //构造消息体
//        JSONObject json = new JSONObject();
//        json.put("message",new UserSend(UUID.randomUUID().toString(),20L, Long.valueOf(obj.toString()),2L));
//        //事务消息封装
//        Message<String> message = MessageBuilder.withPayload(json.toJSONString()).build();
//        log.info("事务消息内容---->{}",json.toJSONString());
//        //事务消息发送
//        TransactionSendResult transactionSendResult = rocketMQTemplate.sendMessageInTransaction("my_tx_group", topic, message, tag);
//        log.info("【事务消息发送后状态】statue:{}",transactionSendResult.getLocalTransactionState());
//        log.info("【消息发送后状态】statue:{}",transactionSendResult.getSendStatus());
//        return transactionSendResult;
//    }
//}
